<template>
	<view class="page">
		<view style="width: 686upx;height: 184upx;background: #FFFFFF;display: flex;margin-top: 24upx;border-radius: 24upx;
		flex-direction: column;margin-left: 32upx;margin-right: 32upx;">
			<view style="color: #191919;font-size: 28upx;margin-top: 32upx;margin-left: 32upx;">提现到</view>
			<view style="display: flex;flex-direction: row;justify-content: space-between;margin-left: 32upx;margin-top: 20upx;">
				<view style="display: flex;flex-direction: row;align-items: center;">
					<image style="width: 40upx;height: 40upx;" src="../../static/images/alipay-img-icon.png" mode=""></image>
					<view style="color: #191919;font-size: 32upx;">支付宝({{encrypAlipayAccount}})</view>
				</view>
					
				<view style="display: flex;flex-direction: row;margin-right: 24upx;align-items: center;" @click="popAliWindow">
					<view style="color: #A6A6A6;font-size: 28upx;">更改</view>
					<image style="width: 28upx;height: 28upx;" src="../../static/images/right-avatar-icon.png" mode="" ></image>
				</view>
			</view>
		</view>
		
		<view style="background: #FFFFFF;border-radius: 24upx;width: 686upx;height: 474upx;
		display: flex;flex-direction: column;margin-top: 24upx;margin-left: 24upx;margin-right: 24upx;">
			
			<view style="margin-top: 32upx;margin-left: 32upx;">
				提现金额
			</view>
			
			<view style="margin-top: 56upx;margin-left: 32upx;">
				<view style="display: flex;flex-direction: row;align-items: center;">
					<image style="width: 32upx;height: 48upx;" src="../../static/images/money-icon.png" mode=""></image>
					<input type="number"  @input="onInput"  v-model="money" style="text-indent: 5upx;margin-left: 5upx;
					font-size: 48upx;font-weight: bold;padding-left: 10upx;" value="" />
				</view>
			</view>
			<view style="border-bottom: 2upx solid #F4F4F4;margin-top: 24upx;margin-left: 24upx;margin-right: 24upx;"></view>
			
			<view style="color: #A6A6A6;font-size: 24upx;margin-top: 16upx;margin-left: 24upx;">可提现余额{{balance}}.00(最低提现30.00)元 
			<span style="color: #FF4E4C;font-size: 24upx;margin-left: 16upx;" @click="allWithdraw">全部提现</span></view>
			
			
			<view style="margin-top: 94upx;" @click="withdraw" v-if="isUnable" > 
				<view style="width: 690upx;height: 80upx;background: #FFBCBB;border-radius: 40upx;
				text-align: center;line-height: 80upx;color: #FFFFFF;"> 提现</view>
			</view>
			<view style="margin-top: 94upx;" @click="withdraw" v-else-if="!isUnable" >
				<view style="width: 690upx;height: 80upx;background: #FF4E4C;border-radius: 40upx;
				text-align: center;line-height: 80upx;color: #FFFFFF;"> 提现</view>
			</view>
		</view>
		
		
		<view class="popup" v-show="show">
			<view class="popup-info">
				<view style="display: flex;flex-direction: row;justify-content: center;align-items: center;">
					<image style="width: 40upx;height: 40upx;" src="../../static/images/alipay-img-icon.png" mode=""></image>
					<view style="color: #191919;font-size: 32upx;font-weight: bold;margin-left: 12upx;">支付宝账号</view>
				</view>
				
				<view style="display: flex;flex-direction: column;align-items: center;margin-top: 40upx;">
					<input style="border: 2upx solid #EDEDED;width: 550upx;height: 80upx;
					border-radius: 16upx;padding-left: 24upx;" type="text" value="" v-model="inputRealName" placeholder="请输入支付宝真实姓名" />
					<input style="border: 2upx solid #EDEDED;width: 550upx;margin-top: 24upx;
					height: 88upx;border-radius: 16upx;padding-left: 24upx;" type="text" value="" v-model="inputAliAccount" placeholder="请输入支付宝账号" />
				</view>
				
				<view style="display: flex;flex-direction: row;align-items: center;justify-content: space-between;margin-top: 56upx;">
					<view style="background: #F4F4F4;color: #191919;font-size: 28upx;width: 240upx;height: 80upx;margin-left: 30upx;border-radius: 40upx;text-align: center;line-height: 80upx;" @tap="cancel">取消</view>
					<view style="background: #FF4E4C;color: #FFFFFF;font-size: 28upx;width: 240upx;height: 80upx;margin-right: 30upx;border-radius: 40upx;text-align: center;line-height: 80upx;" @tap="confrim">确认</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	
	import{apply_withdraw} from '../../api/mine/withdraw.js'
	export default {
		data() {
			return {
				balance:0,
				money:null,
				alipayAccount:"",
				realName:"",
				encrypAlipayAccount:"",
				inputRealName:"",
				inputAliAccount:"",
				show:false,
				isUnable:true
			}
		},
		onLoad(option) {
			console.log(option)
			this.balance=option.amount
			this.alipayAccount=option.alipayAccount
			this.realName=option.realName
			this.encrypAlipayAccount=option.alipayAccount
		},
		onShow() {
			this.money=null
		},
		methods: {
			popAliWindow(){
				this.show=true
			},
			
			// 点击弹窗取消
			cancel() {
				this.show = false;
			},
			// 点击弹窗确认
			confrim() {
				if(this.inputRealName ==='' || this.inputRealName===null){
					uni.showToast({
						icon:'none',
						title:'请输入支付宝真实名称'
					})
					return
				}
				if(this.inputAliAccount ==='' || this.inputAliAccount===null){
					uni.showToast({
						icon:'none',
						title:'请输入支付宝账号'
					})
					return
				}
				this.realName=this.inputRealName;
				this.encrypAlipayAccount=this.inputAliAccount;
				this.alipayAccount=this.inputAliAccount;
				this.show=false
				
				
			},
			allWithdraw(){
				console.log(this.balance)
				if(Number(this.balance)===0){
					return
				}
				this.money=this.balance
				this.isUnable=false
			},
			withdraw(){
				
				if(Number(this.money)>Number(this.balance)){
					uni.showToast({
						icon:'none',
						title:'提现金额超过最大金额'
					})
					return
				}
				if(this.isUnable){
					return
				}
				let params={}
				params.withdrawAmount=this.money;
				params.realName=this.realName;
				params.alipayAccount=this.alipayAccount;
				var that =this
				apply_withdraw(params).then(res=>{
					if(res.status===200){
						that.balance=Number(that.balance)-Number(that.money)
						setTimeout(function() {
							uni.navigateTo({
								url:'../withdraw-success/withdraw-success?money='+that.money+"&account="+that.alipayAccount
							})
						},500)

					}
				})
			},
			
			onInput(e){
				
				let inputMoney=Number(e.detail.value)
				
				if(e.detail.value.indexOf("0")==0){
					this.isUnable=true
					return
				}
				if(inputMoney<30){
					this.isUnable=true
					return
				}
				if(inputMoney>Number(this.balance)|| inputMoney ==='' ||inputMoney ===0){
					
					this.isUnable=true
				}else {
					this.isUnable=false
				}
				
			}
		}
	}
</script>

<style>
	.popup-info {
		position: fixed;
		width: 600upx;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
		padding: 40upx;
		border-radius: 20upx;
		background-color: #fff;
		z-index: 9999;
	}

	.popup {
		position: fixed;
		left: 0;
		right: 0;
		top: 0;
		height: 100vh;
		background-color: rgba(0, 0, 0, 0.6);
		z-index: 9998;
	}
</style>
